package com.danskin.wechat.webapi;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import com.danskin.wechat.entity.WxCardConfig;
import com.danskin.wechat.model.AccessResponse;

import net.sf.json.JSONObject;

@RestController
@RequestMapping("api/card")
public class CardApiController extends BaseApiController {

	@RequestMapping(value = "getWxCardId/{appId}", method = RequestMethod.POST)
	public Object getWxCardId(@RequestBody Map<String, Object> map, @PathVariable("appId") String appId,
			HttpServletRequest request) throws Exception {

		if (!map.containsKey("cardType")) {
			return this.getError("cardType不能为空");
		}
		String cardType = map.get("cardType").toString();
		JSONObject json = null;
		WxCardConfig cardConfig = wechatOpService.findCardConfig(cardType, appId);
		if (cardConfig != null) {
			json = new JSONObject();
			json.put("cardId", cardConfig.getCardId());
		}

		return new AccessResponse<Object>("0", "ok", json);
	}
}
